# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Contributor: Martell Malone <martellmalone@gmail.com>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=py3-numpy
pkgver=2.1.2
pkgrel=0
pkgdesc="Scientific tools for Python"
url="https://www.numpy.org/"
arch="all"
license="BSD-3-Clause"
options="!check"
makedepends="
	cython
	gfortran
	libbsd-dev
	meson
	openblas-dev
	py3-gpep517
	py3-meson-python
	py3-nose
	py3-setuptools
	py3-wheel
	python3-dev
	"
depends="!py3-numpy1"
subpackages="
	$pkgname-dev
	$pkgname-tests
	$pkgname-pyc
	$pkgname-f2py::noarch
	"
source="https://github.com/numpy/numpy/releases/download/v$pkgver/numpy-$pkgver.tar.gz
	numpy-musl.patch
	s390x-hwcap.patch
	site.cfg"
builddir="$srcdir/numpy-$pkgver"

export Atlas=None
# numpy is a huge library (~26 MiB) optimized for performance, so compiling
# with -Os to sacrifice performance for ~1 MiB doesn't make sense.
export CFLAGS="${CFLAGS/-Os/-O3} -flto=auto"
export CXXFLAGS="${CXXFLAGS/-Os/-O3} -flto=auto"

prepare() {
	default_prepare
	cp "$srcdir"/site.cfg "$builddir"/
}

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

f2py() {
	pkgdesc="f2py for numpy (for python3)"
	depends="py3-numpy=$pkgver-r$pkgrel python3-dev"
	install_if="$pkgname-f2py=$pkgver-r$pkgrel python3"

	amove usr/bin/f2py*
}

tests() {
	find "$pkgdir" -name tests -type d | while read -r p; do
		amove "${p#"$pkgdir"}"
	done
}

sha512sums="
3d69f6583e093e8fd0f441ec7dc4658c88fb714bb29574cd9510091ba059553f79c52492037353caf50b6cff1f7bd1e2501e445c7adde41bd9e08bab363e06e9  numpy-2.1.2.tar.gz
34ae8b1c620771517971a563e9326d9d065223058843ebd28f09c8728e8abed20c9d88d20d240bc531738d351a19e222b8ae4d4e41a6f8ba658956bd3c5fcf82  numpy-musl.patch
3b1e0a002f524f36dabaac573245fa0aefb3dd807207b5dcd53a25002cb1e9387fb6db244d715424c903f1a852b344e7bb64d94532cbcbea8b16470d1211b504  s390x-hwcap.patch
3540b5a37a8ea1a09001e1627bee53cf847800f67a24214636f18be43e20a080b0de97ce1036db2ea05e166fd302cc137d632967c443ae422f7dce6dca67c264  site.cfg
"
